#ifndef ENCODER_H
#define ENCODER_H

#ifdef __cplusplus
extern "C"
{
#endif
/*---------------------------- C Scope ---------------------------*/

#include "stdint.h"
#include "fsl_qtmr.h"

#ifdef __cplusplus
}
#endif
/*---------------------------- C++ Scope ---------------------------*/
class Encoder{
private:
    TMR_Type *base=nullptr;
    qtmr_channel_selection_t channel;
    qtmr_counting_mode_t clockSource;
    qtmr_primary_count_source_t phase_a;
    qtmr_input_source_t phase_b;

    int32_t raw_data;
    int32_t last_raw_data;

    float period; //sample time

public:
    int16_t filter_data;
    int16_t filter_data_last;

    Encoder(TMR_Type *_base,qtmr_channel_selection_t _channel,qtmr_counting_mode_t _clockSource,
    qtmr_primary_count_source_t _phase_a,qtmr_input_source_t _phase_b,float _dt = 0.1):
    period(_dt),base(_base),channel(_channel),clockSource(_clockSource),phase_a(_phase_a),phase_b(_phase_b){};
		void Init();
    uint16_t getEncoder();
    void Reload();
    void UpdateRaw();
    int32_t getRawEncoder(); 
		int32_t getLastEncoder(){return last_raw_data;}
		
    float getPeriod(){return period;}

};


#endif
